package leetcode.N201_N300;

import leetcode.comm.ListNode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author xiwai [hww282306@alibaba-inc.com]
 * @version 1.0
 * @date 2020/10/13 8:01 下午
 */
public class N234 {

    public boolean isPalindrome(ListNode head) {
        // 先找到链表的值转移到数组中
        List<Integer> array = new ArrayList<>();
        ListNode current = head;
        while (current != null) {
            array.add(current.val);
            current = current.next;
        }
        int headIndex = 0;
        int tailIndex = array.size() - 1;

        // 前后指针 对比数值
        while (headIndex < tailIndex) {
            if (!array.get(headIndex++).equals(array.get(tailIndex--))) {
                return false;
            }
        }
        return true;
    }
}
